<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>医嘱</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
    <div id="app">
        <el-form ref="form" label-width="80px">
            <el-form-item label="身份证件">
                <el-input v-model="form.patientIdCard" @blur="move" placeholder="请输入身份证" style="width: 200px;"></el-input>
            </el-form-item>
            <el-form-item label="姓名">
                <el-input v-model="patinForm.patientName" :disabled="true" style="width: 150px;"></el-input>
            </el-form-item>
            <el-form-item label="性别">
                <el-input v-model="patinForm.patientSex" :disabled="true" style="width: 150px;"></el-input>
            </el-form-item>
            <el-form-item label="年龄">
                <el-input v-model="patinForm.patientAge" :disabled="true" style="width: 150px;"></el-input>
            </el-form-item>
            <el-form-item label="病例ID">
                <el-input v-model="patinForm.caseId" :disabled="true" style="width: 150px;"></el-input>
            </el-form-item>
            <el-form-item label="医嘱类型">
                <el-select v-model="form.actOrderType" placeholder="请选择类型">
                    <el-option label="长期医嘱" value="长期医嘱"></el-option>
                    <el-option label="短期医嘱" value="短期医嘱"></el-option>
                    <el-option label="临时医嘱" value="临时医嘱"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item >
                <span class="demonstration">医嘱开始和结束时间</span>
                <div class="block" label="医嘱开始和结束时间">

                    <el-date-picker
                            v-model="form.entryDate"
                            type="daterange"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            value-format="yyyy-MM-dd HH:mm:ss"
                    >
                    </el-date-picker>
                </div>
            </el-form-item>
            <el-form-item label="医嘱内容">
                <el-input style="width: 300px" v-model="form.actOrderResult"></el-input>
            </el-form-item>
            <el-form-item label="就诊医生">
                <el-input style="width: 80px" v-model="form.doctorName"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submit">新增医嘱</el-button>

            </el-form-item>

        </el-form>
    </div>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script>
        var app=new Vue({
            el:'#app',
            data:{
                patinForm:{
                    patientIdCard:'',
                    patientName:'',
                    patientAge:'',
                    patientSex:'',
                    caseId:''
                },
                form:{
                    actOrderId:'',
                    actOrderType:'',
                    actOrderStartTime:'',
                    actOrderEndTime:'',
                    actOrderResult:'',
                    doctorName:'',
                    patientIdCard:'',
                    patientName:'',
                    patientAge:'',
                    patientSex:'',
                    caseId:'',
                    entryDate:''
                },

                tableData: [],


            },
            methods:{
                move:function () {
                    var vm=this;
                    console.log(this.form.patientIdCard);
                    const formData=new FormData();
                    formData.append('patientIdCase',this.form.patientIdCard);
                    /*const formData = new FormData();
                    formData.append(patientIdCard,vm.patinForm.patientIdCard);*/
                    axios.post('http://192.168.80.13:8080/medical/act-order/selectAct',formData).then(
                        function (resp) {
                            console.log(resp.data);
                            if(resp.data.data==null||resp.data.data.caseId==null){
                                vm.patinForm.patientName='';
                                vm.patinForm.patientAge='';
                                vm.patinForm.patientSex='';
                                vm.patinForm.caseId='';
                              alert("身份证错误或者你病例已归档");
                            }else {
                                vm.patinForm.patientName=resp.data.data.patientName;
                                vm.patinForm.patientAge=resp.data.data.patientAge;
                                vm.patinForm.patientSex=resp.data.data.patientSex;
                                vm.patinForm.caseId=resp.data.data.caseId;
                                vm.form.patientName=resp.data.data.patientName;
                                vm.form.patientAge=resp.data.data.patientAge;
                                vm.form.patientSex=resp.data.data.patientSex;
                                vm.form.caseId=resp.data.data.caseId;
                                const formData1=new FormData();
                                formData1.append('patientIdCase',vm.form.patientIdCard);
                                formData1.append('caseId',vm.patinForm.caseId);
                                axios.post('http://192.168.80.9:8080/medical/act-order/seleAct',formData1).then(
                                    function (response) {
                                        console.log(response.data);
                                        vm.form.actOrderId=response.data.data.actOrderId;
                                        vm.form.actOrderType=response.data.data.actOrderType;
                                        vm.form.actOrderResult=response.data.data.actOrderResult;
                                        vm.form.doctorName=response.data.data.doctorName;
                                        vm.form.actOrderStartTime=response.data.data.actOrderStartTime;
                                        vm.form.actOrderEndTime=response.data.data.actOrderEndTime;
                                        vm.form.entryDate[0]=response.data.data.actOrderStartTime;
                                        vm.form.entryDate[1]=response.data.data.actOrderEndTime;

                                    }
                                );
                            }
                        }
                    );
                },
                submit:function () {
                    var vm=this;
                    vm.form.actOrderStartTime=vm.form.entryDate[0];
                    vm.form.actOrderEndTime=vm.form.entryDate[1];

                    axios.post('http://192.168.80.13:8080/medical/act-order/submit',vm.form).then(
                        function (resp) {
                            console.log(resp.data);
                            alert(resp.data.message);
                        }
                    )
                }
            },
        });
    </script>
</body>
</html>